<template>
	<view class="header-bar">
		<view class="fill-top" :style="{ height: `${getPadding}px` }"></view>
		<view class="header">
			<view class="city-select" @click="showPicker">
				<view>{{city}}</view>
				<view class="down"></view>
			</view>
			<!--微信小程序端 头部样式-->
			<!--  #ifdef  MP-WEIXIN -->
			<view class="input-search">
				<view class="label">
					<uni-icons color="#B8B8B8" size="22" type="search" />
				</view>
				<view class="search"><input class="search-input" placeholder-class="pla-search" placeholder="关键字搜索" type="text"
					 value="" /></view>
			</view>
			<view class="search-code" @click="scanCode">
				<uni-icons color="#333333" size="28" type="scan" />
				</image>
			</view>
			<!--  #endif -->
			<!--app端 头部样式-->
			<!--  #ifdef  APP-PLUS -->
			<view class="input-search">
				<view class="label">
					<uni-icons color="#B8B8B8" size="22" type="search" />
				</view>
				<view class="search"><input class="search-input" placeholder-class="pla-search" placeholder="关键字搜索" type="text"
					 value="" /></view>
			</view>
			<view class="search-code" @click="scanCode">
				<uni-icons color="#333333" size="30" type="scan" />
				</image>
			</view>
			<!--  #endif -->
		</view>
		<aui-picker ref="picker" :title="auiPicker.title" :layer="auiPicker.layer" :data="auiPicker.data" @callback="pickerCallback"></aui-picker>
	</view>
</template>

<script>
	import {
		cityData
	} from '@/common/city.data.js'; //城市数据
	import auiPicker from '@/components/aui-picker/aui-picker.vue';
	export default {
		components: {
			auiPicker
		},
		data() {
			return {
				city: "上海",
				auiPicker: {
					title: '城市区选择',
					layer: 3,
					data: []
				},
			};
		},
		computed: {
			getPadding() {
				return this.$store.state.systemInfo.statusBarHeight;
			}
		},
		methods: {
			//显示picker多级联动弹窗
			showPicker() {
				this.auiPicker.data = cityData;
				this.$refs.picker.open().then(function() {
					console.log('picker打开');
				});
			},
			//picker多级联动回调
			pickerCallback(e) {
				console.log(e);
				this.city = e.data[1].name.replace(/市/,"")
				if(this.city.length>3){
					this.city = this.city.substring(0,3)+".."
				}
			},
			scanCode() {
				// 只允许通过相机扫码
				uni.scanCode({
					onlyFromCamera: true,
					success(res) {
						console.log(res)
						uni.showModal({
							title: '提示',
							showCancel: false,
							content: JSON.stringify(res),
							success(res) {
								console.log(res);
							}
						});
					}
				});
			}
		}
	};
</script>

<style lang="less">
	.header-bar {
		background: #FFFFFF;
		position: fixed;
		top: 0px;
		z-index: 99;

		.fill-top {
			width: 100vw;
			background: #FFFFFF;
		}

		.header {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			box-sizing: border-box;
			height: 80rpx;
			margin: 3rpx 5vw 3rpx 3vw;
			background: #FFFFFF;

			.city-select {
				width: 17vw;
				height: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				line-height: 60rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #333333;
				white-space:nowrap;
				overflow:hidden;
				text-overflow:ellipsis;

				.down {
					width: 0;
					height: 0;
					overflow: hidden;
					font-size: 0;
					/*是因为, 虽然宽高度为0, 但在IE6下会具有默认的 */
					line-height: 0;
					/* 字体大小和行高, 导致盒子呈现被撑开的长矩形 */
					border-width: 6px;
					border-style: solid;
					/*ie6下会出现不透明的兼容问题*/
					border-color: #333333 transparent transparent transparent;
					margin: 10rpx 0rpx 0rpx 10rpx;
				}
			}

			/* #ifdef MP-WEIXIN */
			.input-search {
				width: calc(100vw - 40vw - 70px);
				display: flex;
				justify-content: flex-start;
				background: #F6F7F8;
				border-radius: 40rpx;

				.label {
					width: 80rpx;
					height: 60rpx;
					text-align: right;
					line-height: 60rpx;
				}

				.search {
					flex: 1;

					.search-input {
						margin-left: 20rpx;
						height: 60rpx;

					}

					.pla-search {
						font-size: 28rpx;
						color: #B8B8B8;
					}
				}
			}

			/* #endif */

			/* #ifdef APP-PLUS */
			.input-search {
				flex: 1;
				display: flex;
				justify-content: flex-start;
				background: #F6F7F8;
				border-radius: 40rpx;

				.label {
					width: 80rpx;
					height: 60rpx;
					text-align: right;
					line-height: 60rpx;
				}

				.search {
					flex: 1;

					.search-input {
						margin-left: 20rpx;
						height: 60rpx;
					}

					.pla-search {
						font-size: 28rpx;
						color: #B8B8B8;
					}
				}
			}

			/* #endif */
			.search-code {
				width: 15vw;
				height: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>
